<?php
require_once(dirname(__FILE__).'/../bootstrap/Doctrine.php');

$t = new lime_test(2, new lime_output_color());

$t->comment('->addOrderByPositionQuery()');
$q = Doctrine::getTable('Tag')->addOrderByPositionQuery();
$t->like($q->getSqlQuery(), '/ORDER BY t.position/', '->addOrderByPositionQuery() adds an order by position to the query');

$t->comment('->retrieveOrderedByPosition()');
$tagList = Doctrine::getTable('Tag')->retrieveOrderedByPosition();
try
{
  $previousPosition = 0;
  foreach ($tagList as $tag)
  {
    if ($tag->position <= $previousPosition)
    {
      throw new Exception('Not sorted by position');
    }
    $previousPosition = $tag->position;
  }
  $t->pass('->retrieveOrderedByPosition() returns tags sorted by position');
}
catch (Exception $e)
{
  $t->fail('->retrieveOrderedByPosition() returns tags sorted by position');
}